const { STRING, INTEGER, BOOLEAN, DATE } = require("sequelize")
// 引入实例
const sequelize = require("../sequelize")
const role = require("./role")

// 建模
const user = sequelize.define("user", {
    username: {
        type: STRING(36),
        allowNull: false, // 非空
        unique: true, // 唯一
        comment: "用户名 唯一值" // 备注
    },
    nickname:{
        type: STRING(36),
        allowNull: false, // 非空
        comment: "昵称" // 备注
    },
    password: {
        type: STRING(128),
        allowNull: false,
        unique: false,
        comment: "密码"
    },
    sex: {
        type: STRING(4),
        comment: "男/女/保密"
    },
    phone: {
        type: STRING(15),
        unique: true,
        comment: "手机号"
    },
    mail: {
        type: STRING(64),
        comment: "邮箱"
    },
    creator: {
        type: STRING,
        comment: "创建者"
    },
    effect: {
        type: BOOLEAN,
        comment: "是否有效 0：无效 ， 1： 有效",
        defaultValue: true
    },
    status: {
        type: BOOLEAN,
        comment: "是否删除",
        defaultValue: false
    },
    avatar: {
        type: STRING,
        comment: "用户头像"
    },
    createdate: {
        type: STRING,
        comment: "创建时间"
    },
    updated: {
        type: STRING,
        comment: "修改时间"
    },
    updator: {
        type: STRING,
        comment: "修改者"
    },
    role_id: {
        type: INTEGER,
        comment: "角色id"
    }
}, { timestamps: false })

user.belongsTo(role, { foreignKey: "role_id", targetKey: "id" })

module.exports = user